import {
  Controller,
  Get,
  Post,
  Put,
  Body,
  Query,
  UseGuards,
  Headers,
  Delete,
  Param,
} from '@nestjs/common';
import {
  ApiBearerAuth,
  ApiOperation,
  ApiResponse,
  ApiParam,
  ApiQuery,
  ApiTags,
} from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';

import { BaseResponse } from '@server/basic-dto';

import ContactService from './service';
import { CreateContactDto, ContactListResponse } from './dto';

@ApiTags('contact')
@Controller('/contact')
export default class ContactController {
  constructor(private readonly service: ContactService) {}

  @ApiOperation({
    summary: '联系我们(提交)',
  })
  @ApiResponse({
    type: BaseResponse,
  })
  @Put('/add')
  async addContact(
    @Body() createContact: CreateContactDto,
  ): Promise<BaseResponse> {
    return this.service.addContact(createContact);
  }

  @UseGuards(AuthGuard())
  @ApiOperation({
    summary: '联系我们分页',
  })
  @ApiResponse({
    type: ContactListResponse,
  })
  @ApiQuery({
    name: 'page',
    description: '当前页',
    required: false,
  })
  @ApiQuery({
    name: 'pageSize',
    description: '每页多少条',
    required: false,
  })
  @ApiQuery({
    name: 'keyword',
    description: '留言模糊匹配',
    required: false,
  })
  @ApiBearerAuth()
  @Get('/list')
  async list(
    @Query('page') page: number,
    @Query('pageSize') pageSize: number,
    @Query('keyword') keyword: string,
  ): Promise<ContactListResponse> {
    return this.service.list(page, pageSize, keyword);
  }
}
